// pages/mine/mine.js
const app = getApp()
import { infoSelfUser, infoSelfModel, myWalletModel, myWalletUser } from '../../api/my';
Page({
  /**
   * 页面的初始数据
   */
  data: {
    navBarHeight: app.globalData.navBarHeight,// 获取导航栏高度
    menuRight: app.globalData.menuRigh,// 获取胶囊距右方间距（方保持左、右间距一致）
    menuTop: app.globalData.menuTop,// 获取胶囊距底部间距（保持底部间距一致）
    menuHeight: app.globalData.menuHeight,// 获取胶囊高度（自定义内容可与胶囊高度保证一致）
    userInfo: {},
    balance: '',
    limits_id: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    //自定义的tabbar
    if (typeof this.getTabBar === 'function' &&
      this.getTabBar()) {
      this.getTabBar().setData({
        selected: 4
      })
    }
    this.getUserDetial()
  },
  getUserDetial() {
    let that = this;
    wx.getStorage({
      key: 'user',
      success(res) {
        console.log(res, 'res.data.id')
        that.setData({
          limits_id: res.data.limits_id
        })
        if (res.data.limits_id == '1') { // 如果是模特身份
          infoSelfModel({ id: res.data.id }).then(data => {
            if (data.data) {
              that.setData({
                userInfo: {
                  ...(data.data || {}),
                  nickname: data.data.nickname || '',
                },
              })
            }
          })
          myWalletModel({ id: res.data.id }).then(data => {
            if (data.data) {
              that.setData({
                balance: data.data.balance ? data.data.balance : 0
              })
            } else {
              that.setData({
                balance: 0
              })
            }
          })
        } else {
          infoSelfUser({ id: res.data.id }).then(data => {
            if (data.data) {
              that.setData({
                userInfo: {
                  ...(data.data || {}),
                  nickname: data.data.nickname || '',
                },
              })
            }
          })
          myWalletUser({ id: res.data.id }).then(data => {
            if (data.data) {
              that.setData({
                balance: data.balance ? data.balance : 0
              })
            } else {
              that.setData({
                balance: 0
              })
            }
          })
        }
      }
    })

  },
  personalInformation: function () {
    wx.navigateTo({
      url: '/subPackages/pages/personalInformation/personalInformation'
    });
  },
  myWallet() {
    wx.navigateTo({
      url: '/subPackages/pages/myWallet/myWallet'
    });
  },
  ModelIntegral() {
    wx.navigateTo({
      url: '/subPackages/pages/ModelIntegral/ModelIntegral'
    });
  },
  myInvite() {
    wx.navigateTo({
      url: '/subPackages/pages/myInvite/myInvite'
    });
  },
  member() {
    wx.navigateTo({
      url: '/subPackages/pages/member/member'
    });
  },
  helpCenter() {
    wx.navigateTo({
      url: '/subPackages/pages/helpCenter/helpCenter'
    });
  },
  Feedback() {
    wx.navigateTo({
      url: '/subPackages/pages/Feedback/Feedback'
    });
  },
  Settings() {
    wx.navigateTo({
      url: '/subPackages/pages/Settings/Settings'
    });
  },
  //订单跳转
  Ordermanagement(e) {
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/subPackages/pages/Ordermanagement/Ordermanagement?id=' + id
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})